#include <iostream>
#include <unordered_set>
#include <vector>
#include <string.h>

using namespace std;

class Solution {
public:
    int countPrimes(int n) {
        if (n <= 1) {
            return 0;
        }
        bool* nums = new bool[n];
        memset(nums, true, n);
        int count = 0;
        bool stop = false;
        for (int i = 2; i < n; i++) {
            if (nums[i]) {
                for (int j = i; j < n; j++) {
                    int val = i * j;
                    if (val >= n) {
                        if (i == j) {
                            stop = true;
                        }
                        break;
                    }
                    nums[val] = false;
                }
            }
            if (stop) {
                break;
            }
        }
        for (int i = 2; i < n; i++) {
            if (nums[i]) {
                count++;
            }
        }
        delete[] nums;
        return count;
    }
};

int main() {
    Solution solution;
    int output = solution.countPrimes(499979);
    cout << output << endl;
    return 0;
}